import request from '@/utils/request';

// 获取课件笔记列表
export function getMaterialList(params) {
  // 确保page和size是数字
  if (params.page) {
    params.page = Number(params.page);
  }
  if (params.size) {
    params.size = Number(params.size);
  }
  
  return request({
    url: '/api/materials/list',
    method: 'get',
    params
  });
}

// 获取课件笔记详情
export function getMaterialDetail(id) {
  return request({
    url: `/api/materials/detail/${id}`,
    method: 'get'
  });
}

// 添加课件笔记
export function addMaterial(data) {
  return request({
    url: '/api/materials/add',
    method: 'post',
    data
  });
}

// 更新课件笔记
export function updateMaterial(data) {
  return request({
    url: '/api/materials/update',
    method: 'put',
    data
  });
}

// 删除课件笔记
export function deleteMaterial(id) {
  return request({
    url: `/api/materials/delete/${id}`,
    method: 'delete'
  });
}

// 上传文件
export function uploadFile(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/files/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 上传封面图
export function uploadCover(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/files/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// AI生成课件/笔记
export function generateAIMaterial(data) {
  return request({
    url: '/api/materials/ai-generate',
    method: 'post',
    data
  });
} 